package com.wyh.controller.feemanagementcontroller;


import com.wyh.common.enums.ResultCodeEnum;
import com.wyh.common.result.Result;
import com.wyh.domain.po.feemanagementpo.PaymentRecords;
import com.wyh.service.feemanagementservice.PaymentRecordsService;
import com.wyh.service.feemanagementservice.RefundService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@Api(tags="退款记录生成")
@RequestMapping("/refund")
public class RefundsController {
    @Autowired
    private RefundService refundService;

    @Autowired
    private PaymentRecordsService paymentRecordsService;

    @ApiOperation("生成退款申请记录")
    @PostMapping("/in")
    public Result insertMe(@RequestBody Map<String, Object> refundRequest) {
        int billid = (int) refundRequest.get("billid");
        refundRequest.remove("billid");

        int paymentRecordId = refundService.insertRefund(refundRequest, billid);
        PaymentRecords a = paymentRecordsService.findByBill(billid);
        if (a.getState() == 1 && paymentRecordId > 0) {
            return Result.success(paymentRecordId);
        } else {
            return Result.error(ResultCodeEnum.SYSTEM_ERROR);
        }
    }


}
